package com.poetize.plus.entity.dto;

import com.poetize.plus.entity.po.Sort;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Null;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Update;

/**
 * @Author zuosy
 * @Date 2024/3/30 16:42
 **/
public record SortDTO(
        @Schema(description = "id")
        @Null(message = "id必须为空", groups = {Insert.class})
        @NotNull(message = "id不能为空", groups = {Update.class})
        Long sortId,

        @Schema(description = "分类名称")
        @NotBlank(message = "分类名称不能为空", groups = {Insert.class, Update.class})
        String sortName,

        @Schema(description = "分类名称")
        @NotBlank(message = "分类名称不能为空", groups = {Insert.class, Update.class})
        String sortDescription
) {

    /**
     * DTO转实体类
     *
     * @param sortDTO
     * @return
     */
    public static Sort convertDTO(SortDTO sortDTO) {
        return new Sort(sortDTO.sortId, sortDTO.sortName, sortDTO.sortDescription);
    }
}
